package com.atguigu.srb.core.controller.admin;


import com.atguigu.common.result.R;
import com.atguigu.srb.core.pojo.entity.IntegralGrade;
import com.atguigu.srb.core.service.IntegralGradeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 积分等级表 前端控制器
 * </p>
 *
 * @author 杜佳佳
 * @since 2021-04-13
 */
@Api(tags = "积分等级管理")
@RestController
@RequestMapping("/admin/core/integralGrade")
@Slf4j
public class AdminIntegralGradeController {

    @Autowired
    private IntegralGradeService integralGradeService;

    @ApiOperation("积分等级列表")
    @GetMapping("/allList")
    public R list() {
        List<IntegralGrade> list = integralGradeService.list();
        return R.ok().data("list",list).message("获取积分等级列表成功");
    }
    @ApiOperation("根据id删除")
    @DeleteMapping("/delete/{id}")
    public R delete(@ApiParam("积分等级id") @PathVariable Long id){
        integralGradeService.removeById(id);
        return R.ok().message("删除积分等级成功");
    }

    @PostMapping("/save")
    public R save(@RequestBody IntegralGrade integralGrade) {
        integralGradeService.save(integralGrade);
        return R.ok();
    }
    @GetMapping("/info/{id}")
    public R info(@PathVariable Long id){
        IntegralGrade byId = integralGradeService.getById(id);
        return R.ok().data("data",byId);
    }

    @PutMapping("/update")
    public R update(@RequestBody IntegralGrade integralGrade) {
        integralGradeService.updateById(integralGrade);
        return R.ok();
    }


}

